/*
 * @Author: funlee
 * @Email: i@funlee.cn
 * @Date: 2018-05-06 10:38:21
 * @Description: 用代理实现单例模式
 */
const log = console.log.bind();
log('---用代理实现单例模式 ---');

var CreateDiv = function (html) {
  this.html = html;
  this.init();
}
CreateDiv.prototype.init = function () {
  var div = document.createElement('div');
  div.innerHTML = this.html;
  document.body.appendChild(div);
}

var ProxySingletonCreateDiv = (function () {
  var instance;
  return function (html) {
    if (!instance) {
      instance = new CreateDiv(html);
    }
    return instance;
  }
})();

var a = new ProxySingletonCreateDiv('seven1');
var b = new ProxySingletonCreateDiv('seven2');

log(a === b)

